package com.tuju.jetpackfirstdemo.ui.log

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.bumptech.glide.Glide
import com.tuju.jetpackfirstdemo.R
import com.tuju.jetpackfirstdemo.data.Resource
import com.tuju.jetpackfirstdemo.ui.weather.WeatherViewModel
import com.tuju.jetpackfirstdemo.utils.InjectorUtil
import com.tuju.jetpackfirstdemo.utils.showToast
import kotlinx.android.synthetic.main.activity_log.*
import kotlinx.android.synthetic.main.activity_weather.*

class LogActivity : AppCompatActivity() {
    lateinit var viewModel: WeatherViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_log)
        viewModel = ViewModelProviders.of(this, InjectorUtil.getWeatherFactory()).get(WeatherViewModel::class.java)
        initView()
    }

    fun initView() {
        btn_normal_get.setOnClickListener {
            observeBindPic(viewModel.getBingPic())
        }
    }

    private fun observeBindPic(liveData: LiveData<Resource<String>>) {
        liveData.observe(this, Observer { result ->
            if (result?.data != null && result.state == Resource.SUCCESS) {
                Log.i("yanze_log",result.data)
            } else {
                showToast(msg = result?.message!!)
            }
        })
    }

}